package com.style_transfer.util;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class CookieUtil {
    //设置Cookie
    public static void setCookie(HttpServletResponse response, String name, String value, int expiry){
        Cookie cookie = new Cookie(name, value); //key 为cookie内容名字，value为cookie 类型
        cookie.setMaxAge(expiry);       //cookie过期时间
        cookie.setPath("/localhost:8080");
        response.addCookie(cookie);
    }

    //获取所有Cookie
    public static Map<String, String> getCookies(HttpServletRequest request,String name){
        Map<String, String> map = new HashMap<>();
        Cookie cookies[] = request.getCookies();
        if (cookies != null){
            return map;
        }
        return null;
    }

}
